<?php

class AgentListing extends AbstractBox {
	
	protected $template = 'reality/agent-listing.tpl';
	
	protected $pageList = array();
	protected $pageUidList = array();
	protected $onPage = 6;
	
	protected function setup() {
		$agentRepository = new AgentRepository();
		$agentRepository->setLimit($this->onPage);
		
		$page = 1;
		if (Utils::get('page')) {
			$page = intval(Utils::get('page'));
		}
		MySmarty::assign('page', $page);
		$agentRepository->setPage($page);
		
		$agentRepository->addOrderBy(array('name' => 'ASC'));

		$agentList = $agentRepository->getAll();
		$count = $agentRepository->getCountAll();
		
		$pages = array();
		$pageCount = ceil($count / $this->onPage);
		if ($pageCount > 1) {
			for ($i = 1; $i <= $pageCount; $i++) {
				$pages[] = $i;
			}
		}
		MySmarty::assign('pageCount', $pageCount);
		MySmarty::assign('pages', $pages);
		MySmarty::assign('actualState', Utils::get());
		MySmarty::assign('agentList', $agentList);
		MySmarty::assign('actualUrlWithoutGetParameters', Utils::getActualUrlWithoutGetParameters());
	}
	
	protected function getAllPagesRecursive($parentList) {
		$pageRepository = new PageRepository();
		$pages = $pageRepository->getByPid($parentList);
		
		if ($pages) {
			$pageUidList = array();
			foreach ($pages as $page) {
				$this->pageList[] = $page;
				$this->pageUidList[] = $page['uid'];
				$pageUidList[] = $page['uid'];
			}
			$this->getAllPagesRecursive($pageUidList);
		}
	}
}

?>